<template>
	<view class="content" >
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="约稿设置" titleStyle="{'color': '#000'}">
			
		</u-navbar>
	
		<view class="baibox" >
			<view class="baili" @click="$go('/showcase/showcase/showcase')">
				<view class="txt">
					橱窗内容设置
					<view class="tip">
						展示在首页的橱窗内容，可供用户下单
					</view>
				</view>
				<view class="right">
					<text class="status act" v-if="info.is_chu>0">已填写</text>
					<text class="status" v-else >未填写</text>
					<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
				</view>
			</view>
			
			<view class="baili" @click="$go('/pages/user/notice')">
				<view class="txt">
					约文须知填写
					<view class="tip">
						展示在主页“沟通”栏，可供用户查阅
					</view>
				</view>
				<view class="right">
					<text class="status act" v-if="info.is_cont==1">已填写</text>
					<text class="status" v-else >未填写</text>
					<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
				</view>
			</view>
			<view class="baili" @click="$go('/pages/user/manage')">
				<view class="txt">
					推荐展示设置
					<view class="tip">
						可对推荐展示的价格和标签进行设置
					</view>
				</view>
				<view class="right">
					<text class="status act" v-if="info.is_show==1">已填写</text>
					<text class="status" v-else >未填写</text>
					<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
				</view>
			</view>
		</view>
		<view class="baibox">
	
			<view class="baili" >
				<view class="txt">
					推荐展示开关
					<view class="tip">
						关闭将不再向其他用户推荐您的信息
					</view>
				</view>
				<u-switch v-model="info.order_receiving_status" :inactiveValue="0"
					:activeValue="1" inactiveColor="#888EB6" size="20" activeColor="#7BF0D9"
					@change="saveWriterUserConfig"></u-switch>
			</view>
		</view>
	
	</view>
</template>
<script>
	export default {
		data() {
			return {
				type:0,
				// 字数
				index: 0,
				// 开关
				value: false,
				// 弹框
				show: false,
				info:{
					order_receiving_status:0,
					is_chu:0,
					is_cont:0,
					is_show:0
				}
			}
		},
		onLoad() {

		},

		onShow() {
			this.getUserInfo()
			if(!this.$db.get('config') || this.$db.get('config') ==null || this.$db.get('config') == undefined){
				console.log("config")
				this.getConfig();
			}
		},
		methods: {
			saveWriterUserConfig() {
				var that = this
				if(this.info.order_receiving_status == 1){
					if (this.info.is_chu == 0) {
						this.info.order_receiving_status = 0
						this.$common.errorToShow('没有审核通过橱窗',()=>{
						
						},1000)
						return
					}
					if (this.info.is_cont == 0) {
						this.info.order_receiving_status = 0
						this.$common.errorToShow('约文须知必须填写',()=>{
						
						},1000)
						return
					}
					if (this.info.is_show == 0) {
						this.info.order_receiving_status = 0
						this.$common.errorToShow('推荐展示设置必须填写',()=>{
						
						},1000)
						return
					}
				}
				
				this.$api.default.request('good/list', {
					page: 1
				}).then((res) => {
					if (res.code) {
						if (res.data.total) {
							that.$api.default.request('user/saveWriterUserConfig',{
								order_receiving_status:this.info.order_receiving_status
								
							}, 'POST', false).then((
								res) => {
									if (res.code == 1) {
										console.log(res.msg)
									} else {
										that.$common.errorToShow(res.msg, () => {
											that.userInfo.writer_user_config.order_receiving_status = 0
										})
									}
								})
						} else {
							that.$common.errorToShow('请先上传橱窗商品', () => {
								that.userInfo.writer_user_config.order_receiving_status = 0
							})
			
						}
					}
				})
			},
			getUserInfo() {
				//get_rule 推荐的开关？
				
				this.$api.default.request('user/get_rule', {}, 'POST', false).then((res) => {
					if (res.code) {
						this.info = res.data
					}
				})
			}
			
		}
	}
</script>
<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}
	.content {
		padding-top: 20rpx;
		
		.baibox{
			background-color: #ffffff;
			padding: 0 30rpx;
			margin-bottom: 20rpx;
			.baili:last-child{
				border: none;
			}
			.baili{
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 120rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
				
				.txt{
					flex-grow: 1;
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					flex-shrink: 0;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.tip{
						font-size: 24rpx;
						font-weight:normal;
						color: #999999;
					}
				}
				.right{
					display: flex;
					align-items: center;
					.status{
						font-size: 28rpx;
						font-weight: normal;
						color: #999;
						margin-right: 20rpx;
					}
					.act{
						color: #45C4B0;
					}
				}
				.cenbox{
					flex-grow: 1;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					padding: 0 16rpx;
					.headpic{
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
					}
					.centxt{
						font-size: 28rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						color: #999999;
						width: 440rpx;
					}
					.is_auth{
						color:#45C4B0;
					}
					.is_no_auth{
						color:#999;
					}
					.qianbox{
						text-align: right;
						width: 450rpx;
						white-space: nowrap;
						.qli{
							background: rgba(153, 153, 153, 0.1);
							padding: 3rpx 12rpx 4rpx 8rpx;
							border-radius: 178px;
							font-size: 24rpx;
							color: #3D3D3D;
							display: inline-block;
						}
						.qli:not(:first-child){
							margin-left: 16rpx;
						}
					}
				}
				.rarr{
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}
			}
		}
		.mask{
			background: #F2F5F2;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			overflow: hidden;
			.manei{
				margin-bottom: 20rpx;
				background-color: #ffffff;
				.matop{
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 40rpx 50rpx ;
					border-bottom: 1px solid rgba(153, 153, 153, 0.1);
					
					.mapic{
						width: 40rpx;
						height: 40rpx;
						flex-shrink: 0;
					}
					.matxt{
						flex-grow: 1;
						font-size: 28rpx;
						padding: 0 16rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}
			}
			
			.qubox{
				line-height: 120rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
				height: 120rpx;
				opacity: 1;
				background: #FFFFFF;
			}
		}
	}
</style>